import { getFormFields } from '@/utils/formUtils'
import type { FormFieldConfig } from '@/types/form'
import { useConsultPlanStore } from '@/store/consultPlanStore'

// 表格列配置
export const tableColumns = [
  {
    title: 'ID',
    dataIndex: 'id',
  },
  {
    title: '診金分成方案',
    dataIndex: 'consultPlanTitle',
  },
  {
    title: '開始時間',
    dataIndex: 'startDate',
  },
  {
    title: '結束時間',
    dataIndex: 'endDate',
    customRender: ({value}) => {
      return value || '未知'
    },
  },
  {
    title: '狀態',
    dataIndex: 'status',
  },
  {
    title: '修改人',
    dataIndex: 'updatedBy',
  },
  {
    title: '修改時間',
    dataIndex: 'updatedAt',
  },
  {
    title: '操作',
    key: 'action',
    align: 'center',
  },
]


// 表單字段配置
const FormField: Record<string, FormFieldConfig> = {
  consultPlanId: {
    label: '診金分成方案',
    type: 'select',
    placeholder: '請選擇診金分成方案',
    rules: [{ required: true, message: '請選擇診金分成方案' }],
    options: [],
  },
  validDate: {
    label: '有效日期',
    type: 'daterange',
  },

}

export const getCreteFieldConfig = async (fields?: string[]) => {
  const consultPlanOptions = await getConsultPlanOptions()
  FormField.consultPlanId.options = consultPlanOptions
  return getFormFields(FormField, fields)
}

export const getEditFieldConfig = async (fields?: string[]) => {
  const consultPlanOptions = await getConsultPlanOptions()
  FormField.consultPlanId.options = consultPlanOptions
  return getFormFields(FormField, fields)
}

// 獲取診金方案選項
export const getConsultPlanOptions = async () => {
  const consultPlanStore = useConsultPlanStore()
  const options = await consultPlanStore.fetchOptions()
  return options;
}
